package com.ideabove.heart.data;

import java.util.ArrayList;
import java.util.List;

import com.ideabove.heart.CallListActivity;
import com.ideabove.heart.MoeActivity;
import com.ideabove.heart.MorningCallActivity;
import com.ideabove.heart.R;
import com.ideabove.heart.manager.AppManager;
import com.ideabove.heart.manager.MoeManager;
import com.ideabove.heart.manager.ScheduleManager;
import com.ideabove.heart.schedule.ScheduleInfo;
import com.ideabove.heart.util.LogUtil;


import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CallListAdapter extends BaseAdapter{

	private List<ScheduleInfo> mList;
	private LayoutInflater mInflater;  
	private CallListActivity activity;
	private boolean isEditable = false; // 1: edit mode

	public CallListAdapter(CallListActivity activty, ArrayList<ScheduleInfo> arrays ){
		this.mInflater = LayoutInflater.from(activty);
		this.mList = arrays;
		this.activity = activty;
	}

	public void setEditMode(boolean isEditable){
		this.isEditable = isEditable;
	}
	
	public boolean isEditMode(){
		return isEditable; 
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{

		if(convertView == null)
		{
			convertView = mInflater.inflate(com.ideabove.heart.R.layout.row_call_list, null);			
		}

		final ScheduleInfo info = mList.get(position);
//		final View rowView = convertView;
//		final int rowPos = position;
		if (info != null) {
			// playitem을 넣어줌
			
			convertView.setTag(info);
			
			ImageView call_list_face = (ImageView) convertView.findViewById(R.id.call_list_face);			
			String rpName = info.getRpImg();
			
			Bitmap bitmap = MoeManager.loadDataFromAsset(rpName, activity);			
			call_list_face.setImageBitmap(bitmap);
			
						
			TextView call_list_idx = (TextView) convertView.findViewById(R.id.call_list_idx);
			call_list_idx.setText(String.valueOf(info.getId() - 1));
		
			LinearLayout  layout = (LinearLayout)convertView.findViewById(R.id.row_call_list);
			layout.setContentDescription(info.getEp());
			layout.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// 해야할 일은...... 이전 모에 플레이
					MoeManager.setWhatWillIdo(MoeManager.DO_EP_PLAY,v.getContentDescription().toString());
					Intent intent = new Intent(activity, MoeActivity.class);
					activity.startActivity(intent);
					AppManager.pause(activity);
				}
			});			
		}
		
		Animation animation = AnimationUtils.loadAnimation(activity, android.R.anim.fade_in);
		convertView.startAnimation(animation);
		return convertView;
	}

	@Override
	public int getCount() {
		return mList.size();
	}
	@Override
	public ScheduleInfo getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

}
